<!--  -->
<template>
  <div class="app-container">
    <div class="df">
      <el-button type="warning" icon="el-icon-edit" style="marginRight:15px" @click="add">添加</el-button>

      <span>弹窗刷新时间设置：</span>
      <el-time-picker
        v-model="time"
        size="normal"
        :editable="false"
        style="width:100px"
        value-format="HH:mm"
        format="HH:mm"
        placeholder="任意时间点"
      ></el-time-picker>
      <span style="margin:0 15px 0 10px">ms</span>
      <el-button type="primary" icon="el-icon-check" @click="save">保存</el-button>
      <el-button icon="el-icon-refresh" style="marginRight:15px" @click="refresh">重置</el-button>
    </div>
    <el-table :data="sliderData" border stripe>
      <template v-for="(i, index) in columns">
        <el-table-column
          v-if="index == 1"
          :prop="i.data"
          :key="i.id"
          :label="i.label"
          align="center"
          :width="i.width"
        >
          <template slot-scope="scope">
            <el-image
              class="slideImg"
              :src="scope.row.image"
              fit="fill"
              :lazy="true"
              :previewSrcList="[scope.row.image]"
            ></el-image>
          </template>
        </el-table-column>
        <el-table-column
          v-else-if="index == 5"
          :prop="i.data"
          :key="i.id"
          :label="i.label"
          align="center"
          :width="i.width"
        >
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.isUsed"
              :active-value="true"
              :inactive-value="false"
              @change
            ></el-switch>
          </template>
        </el-table-column>
        <el-table-column
          v-else
          :prop="i.data"
          :key="i.id"
          :label="i.label"
          align="center"
          :width="i.width"
        ></el-table-column>
      </template>

      <el-table-column align="center" label="操作" width="200">
        <template slot-scope="scope">
          <el-button type="primary" size="small" @click="edit(scope)">编辑</el-button>
          <el-button type="danger" size="small" @click="del(scope)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <div class="page">
      <el-pagination
        @size-change="sizeChange"
        @current-change="currentChange"
        :current-page.sync="page"
        :page-sizes="[20, 40, 80, 100]"
        :page-size="limit"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        background
      ></el-pagination>
    </div>

    <!-- 对话框 -->
    <el-dialog
      :title="dialogTitle"
      :visible.sync="showDialog"
      width="40%"
      @close="showDialog = false"
    >
      <el-form
        :model="addForm"
        ref="form"
        :rules="rules"
        label-width="120px"
        :inline="false"
        size="normal"
      >
        <el-form-item label="编号" prop="id">
          <el-input v-model="addForm.id" style="width:60%"></el-input>
        </el-form-item>
        <el-form-item label="弹窗海报" prop="cover">
          <el-upload
            action
            :file="addForm.cover"
            :before-upload="beforeCoverUpload"
            list-type="picture-card"
            accept="image/*"
          >
            <i class="el-icon-plus"></i>
            <div slot="tip" class="el-upload__tip">只能上传不超过 2MB 的image/*文件</div>
          </el-upload>
        </el-form-item>
        <el-form-item label="弹窗名称" prop="name">
          <el-input v-model="addForm.name" style="width:60%"></el-input>
        </el-form-item>
        <el-form-item label="是否启用" prop="status">
          <el-switch v-model="addForm.status" :active-value="true" :inactive-value="false" @change></el-switch>
        </el-form-item>
        <el-form-item label="跳转链接" prop="url">
          <el-input v-model="addForm.url" style="width:60%"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click>立即创建</el-button>
          <el-button>取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "slider",
  data() {
    return {
      time: "0:00",
      dialogTitle: "创建",
      showDialog: false,
      page: 1,
      limit: 10,
      total: 10,
      sliderData: [
        {
          id: "1",
          image:
            "https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg",
          introduce: "说明1说明1说明1说明1说明1说明1",
          herfType: "了解了解了解了解",
          sortOrder: 1,
          isUsed: true
        },
        {
          id: "2",
          image:
            "https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg",
          introduce: "说明1说明1说明1说明1说明1说明1说明1",
          herfType: "了解了解了解了解",
          sortOrder: 2,
          isUsed: true
        },
        {
          id: "3",
          image:
            "https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg",
          introduce: "说明3说明1说明1说明1说明1说明1",
          herfType: "了解了解了解了解",
          sortOrder: 3,
          isUsed: true
        }
      ],

      addForm: "",
      rules: {
        id: [{ required: true }],
        cover: [{ required: true }],
        name: [{ required: true }],
        status: [{ required: true }],
        url: [{ required: true }]
      },

      columns: [
        { key: 0, label: `编号`, data: "id", visible: true, width: "80" },
        { key: 1, label: `引导页海报`, data: "image", visible: true },
        { key: 2, label: `引导页文案`, data: "introduce", visible: true },
        {
          key: 2,
          label: `跳过时间`,
          data: "sortOrder",
          visible: true,
          width: "100"
        },
        {
          key: 3,
          label: `跳转链接`,
          data: "herfType",
          visible: true,
          width: "250"
        },
        {
          key: 4,
          label: `是否启用`,
          data: "isUsed",
          visible: true,
          width: "100"
        }
      ]
    };
  },
  methods: {
    add() {
      this.showDialog = true;
    },
    edit() {
      this.showDialog = true;
    },
    del() {
      this.$confirm("确认删除所选数据？", "确认删除", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true
      })
        .then(() => {
          this.$message.warning("删除成功！");
          this.tableData.splice(i, 1);
        })
        .catch(() => {});
    },
    save() {
      this.$message.success('保存成功！')
    },
    refresh() {
      this.$message.success('重置成功！')
    },
    sizeChange() {},
    beforeCoverUpload() {},
    currentChange() {}
  }
};
</script>
<style scoped>
.df {
  margin-bottom: 15px;
}
.slideImg {
  width: 140px;
}
</style>
